<template>
	<view class="login">
		<image class="logo" src="../../../static/icons/leju-logo.png" mode=""></image>

		<view class="input-holder">
			<input type="text" v-model="userData.username" />
			<input type="password" v-model="userData.password" />
		</view>

		<view class="login-btn" @tap="doLogin">
			登 录
		</view>

		<view class="bottom-btn">
			<view class="btn" @tap="toForgetPassword">
				找回密码
			</view>
			<view class="line">
				|
			</view>
			<view class="btn" @tap="toRegister">
				注册账号
			</view>
		</view>
	</view>
</template>

<script>
	import {
		requestLogin
	} from 'api/user/login.js';
	export default {
		data() {
			return {
				userData: {
					"username": "11451422",
					"password": "123456"
				}
			}
		},
		methods: {
			// 登录
			doLogin() {
				if (this.userData.username) {
					if (this.userData.password) {
						requestLogin(this.userData).then(res => {
							if(res.code===20000){
								uni.setStorageSync('token',res.data.token);
								uni.switchTab({
									url:'/pages/user/user'
								})
							}
							console.log(res);
						})
					} else {
						uni.showToast({
							title: '请输入密码',
							icon:'none'
						})
					}
				} else {
					uni.showToast({
						title: '请输入用户名',
						icon:'none'
					})
				}
			},
			
			// 跳转到注册界面
			toRegister(){
				uni.navigateTo({
					url:'/pages/user/login/register/register'
				})
			},
			// 跳转到注册界面
			toForgetPassword(){
				uni.navigateTo({
					url:'/pages/user/login/foget-password/foget-password'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.login {
		box-sizing: border-box;
		padding: 0 70rpx;
		min-height: 100vh;
		width: 100%;

		.logo {
			display: block;
			margin: 0 auto;
			margin-top: 128rpx;
			width: 80px;
			height: 80px;
			border-radius: 50%;
			box-shadow: 0px 0px 60rpx 0px rgba(0, 0, 0, .1);
		}

		.input-holder {
			margin-top: 100rpx;

			input {
				box-sizing: border-box;
				margin-top: 32rpx;
				padding: 32rpx;
				height: 100rpx;
				width: 100%;
				border-radius: 50rpx;
				box-shadow: 0 0 30px 0 rgba(43, 86, 112, .1);
			}
		}

		.login-btn {
			box-sizing: border-box;
			margin-top: 100rpx;
			padding: 32rpx;
			height: 100rpx;
			width: 100%;
			font-size: 32rpx;
			color: rgb(255, 255, 255);
			border-radius: 50rpx;
			box-shadow: 0 0 30px 0 rgba(43, 86, 112, .1);
			background: rgb(53, 78, 68);
			text-align: center;
		}

		.bottom-btn {
			margin-top: 60rpx;
			display: flex;
			justify-content: center;

			.line {
				margin: 0 10rpx;
			}
		}
	}
</style>
